package com.app.milkteaapp.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.app.milkteaapp.R;
import com.app.milkteaapp.fragment.MilkteaFragment;
import com.app.milkteaapp.fragment.ShopCartFragment;
import com.app.milkteaapp.fragment.UserFragment;

public class HomepageActivity extends AppCompatActivity implements View.OnClickListener{

    private FrameLayout fragment;
    private ImageView milktea;
    private ImageView ShoppingCart;
    private ImageView user;
    FragmentManager fm;
    FragmentTransaction ft;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_homepage);
        initView();
    }

    private void initView() {
        fragment = (FrameLayout) findViewById(R.id.fragment);
        milktea = findViewById(R.id.milktea);;
        ShoppingCart =  findViewById(R.id.ShoppingCart);
        user = findViewById(R.id.user);

        milktea.setOnClickListener(this);
        ShoppingCart.setOnClickListener(this);
        user.setOnClickListener(this);

        fm =getSupportFragmentManager();
        ft = fm.beginTransaction();
        ft.replace(R.id.fragment,new MilkteaFragment());
        ft.commit();
    }

    @Override
    public void onClick(View view) {
        fm =getSupportFragmentManager();
        ft = fm.beginTransaction();
        switch (view.getId()){
            case R.id.milktea:
                ft.replace(R.id.fragment,new MilkteaFragment());
                ft.commit();
                break;
            case R.id.ShoppingCart:
                ft.replace(R.id.fragment,new ShopCartFragment());
                ft.commit();
                break;
            case R.id.user:
                ft.replace(R.id.fragment,new UserFragment());
                ft.commit();
                break;
        }
    }
}
